package com.ruoyi.project.bajiaostar.tGood.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.bajiaostar.tGood.domain.TGood;
import com.ruoyi.project.bajiaostar.tGood.service.ITGoodService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品Controller
 * 
 * @author wangwu
 * @date 2024-05-20
 */
@Controller
@RequestMapping("/bajiaostar/tGood")
public class TGoodController extends BaseController
{
    private String prefix = "bajiaostar/tGood";

    @Autowired
    private ITGoodService tGoodService;

    @RequiresPermissions("bajiaostar:tGood:view")
    @GetMapping()
    public String tGood()
    {
        return prefix + "/tGood";
    }

    /**
     * 查询商品列表
     */
    @RequiresPermissions("bajiaostar:tGood:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGood tGood)
    {
        startPage();
        List<TGood> list = tGoodService.selectTGoodList(tGood);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
    @RequiresPermissions("bajiaostar:tGood:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGood tGood)
    {
        List<TGood> list = tGoodService.selectTGoodList(tGood);
        ExcelUtil<TGood> util = new ExcelUtil<TGood>(TGood.class);
        return util.exportExcel(list, "tGood",null);
    }

    /**
     * 新增商品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品
     */
    @RequiresPermissions("bajiaostar:tGood:add")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGood tGood)
    {
        return toAjax(tGoodService.insertTGood(tGood));
    }

    /**
     * 修改商品
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TGood tGood = tGoodService.selectTGoodById(id);
        mmap.put("tGood", tGood);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品
     */
    @RequiresPermissions("bajiaostar:tGood:edit")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGood tGood)
    {
        return toAjax(tGoodService.updateTGood(tGood));
    }

    /**
     * 删除商品
     */
    @RequiresPermissions("bajiaostar:tGood:remove")
    @Log(title = "商品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGoodService.deleteTGoodByIds(ids));
    }
}
